package com.xk857.simpleeffect.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.xk857.simpleeffect.R;
import com.xk857.simpleeffect.domain.entity.Opinion;

import java.util.List;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;

public class ListOpinionAdapter extends BaseQuickAdapter<Opinion, ListOpinionAdapter.ViewHolder> {

    private final Context mContext;


    public ListOpinionAdapter(Context mContext, List<Opinion> opinionList) {
        super(opinionList);
        this.mContext = mContext;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup parent, int i) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.list_opinion, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, int i, @Nullable Opinion opinion) {
        holder.titleView.setText(opinion.getTitle());
        holder.contentText.setText(opinion.getContent());
        if (StrUtil.isBlank(opinion.getReply())) {
            holder.replyText.setVisibility(View.GONE);
            holder.replyText.setText(opinion.getReply());
        }
        // 0未处理 1处理中 2已解决 3无法重现 4已采纳
        if (opinion.getStatus() == 0) {
            holder.statusText.setText(" · 未处理");
            holder.statusText.setTextColor(mContext.getColor(com.xuexiang.xui.R.color.xui_config_color_red));
        } else if (opinion.getStatus() == 1) {
            holder.statusText.setText(" · 处理中");
            holder.statusText.setTextColor(mContext.getColor(R.color.xui_config_color_light_blue));
        } else if (opinion.getStatus() == 2) {
            holder.statusText.setText(" · 已解决");
            holder.statusText.setTextColor(mContext.getColor(com.xuexiang.xui.R.color.xui_btn_green_normal_color));
        } else if (opinion.getStatus() == 3) {
            holder.statusText.setText(" · 无法重现");
            holder.statusText.setTextColor(mContext.getColor(com.xuexiang.xui.R.color.xui_config_color_waring));
        } else if (opinion.getStatus() == 4) {
            holder.statusText.setText(" · 已解决");
            holder.statusText.setTextColor(mContext.getColor(R.color.success));
        }

        if (opinion.getType() == 1) {
            holder.typeText.setText("BUG");
            holder.typeText.setTextColor(mContext.getColor(com.xuexiang.xui.R.color.xui_config_color_red));
        } else {
            holder.typeText.setText("建议");
            holder.typeText.setTextColor(mContext.getColor(R.color.success));
        }


        String createTime = LocalDateTimeUtil.format(opinion.getCreateTime(), "MM月dd日 HH:mm:ss");
        holder.createTimeText.setText(createTime);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView titleView;
        TextView statusText;
        TextView contentText;
        TextView replyText;
        TextView typeText;
        TextView createTimeText;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            titleView = itemView.findViewById(R.id.title_view);
            statusText = itemView.findViewById(R.id.status_text);
            contentText = itemView.findViewById(R.id.content_text);
            replyText = itemView.findViewById(R.id.reply_text);
            typeText = itemView.findViewById(R.id.type_text);
            createTimeText = itemView.findViewById(R.id.create_time_text);
        }
    }
}
